package org.lex.explorer.file;

import java.awt.Window;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import org.lex.swing.ActionBuilder;

public class AbstractFileAction extends ActionBuilder {
	protected FileExplorer fileExplorer = null;

	public AbstractFileAction(FileExplorer fileExplorer) {
		super();
		this.fileExplorer = fileExplorer;
	}

	protected boolean confirm(String title, String msg) {
		int opt = JOptionPane.showConfirmDialog(this.getRootWindow(), msg, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
		if (JOptionPane.YES_OPTION == opt)
			return true;
		return false;
	}

	protected String input(String title, String msg, String initialValue) {
		Object o = JOptionPane.showInputDialog(this.getRootWindow(), msg, title, JOptionPane.QUESTION_MESSAGE, null, null, initialValue);
		if (null == o)
			return null;
		return o.toString();
	}

	protected void message(String title, String msg) {
		JOptionPane.showMessageDialog(this.getRootWindow(), msg, title, JOptionPane.INFORMATION_MESSAGE);
	}

	protected void error(String title, String msg) {
		JOptionPane.showMessageDialog(this.getRootWindow(), msg, title, JOptionPane.ERROR_MESSAGE);
	}

	protected Window getRootWindow() {
		return SwingUtilities.getWindowAncestor(fileExplorer);
	}
}
